package touchtrack;

import java.io.File;

import org.mt4j.MTApplication;

import touchtrack.controller.ArtistController;
import touchtrack.controller.TrackController;
import touchtrack.model.World;
import touchtrack.util.FileDrop;
import touchtrack.util.TrackLoader;
import touchtrack.view.scene.TrackGraphScene;

/**
 * Start
 * 
 * Bootstrap class for our multimedia project "TouchTrack".
 * 
 * @author	MuMe09 team 6
 * 			http://mumetech.wordpress.com/
 */
public class TouchTrack extends MTApplication
{
	/**
	 * Bootstrap procedure.
	 * 
	 * @param 	args
	 */
	public static void main(String[] args) 
	{
		initialize();
	}
    
    public static final int APPLET_WIDTH = 600;
    public static final int APPLET_HEIGHT = 600;
	
	@Override
	public void startUp()
	{
		// load world
		world = new World();
		
		// load controllers
		artistController = new ArtistController(world);
		trackController = new TrackController(world);
        
		// add scenes
		final TrackGraphScene tgs = new TrackGraphScene(this, artistController, trackController);
		addScene(tgs);
        
		// file loader
		final TrackLoader loader = new TrackLoader(artistController, trackController);
		
		// file drop functionality
		new FileDrop(this, new FileDrop.Listener() {
			public void filesDropped(File[] files)
			{
				tgs.pause();
				for (File f : files)
				{
					try 
					{
						loader.load(f);
						tgs.getGraph().createGraph();
					} 
					catch (Throwable t)
					{
						t.printStackTrace();
					}
				}
				tgs.unpause();
			}
		});
		
		/*// load mp3
		File mp3 = null;
		String wd = System.getProperty("user.dir");
        JFileChooser fc = new JFileChooser(wd);
        fc.addChoosableFileFilter(new MP3Filter());
        int rc = fc.showDialog(null, "Select MP3 File");
        if (rc == JFileChooser.APPROVE_OPTION)
        	mp3 = fc.getSelectedFile();
        else
            System.exit(0);
        */
	}
	
	/**
	 * Inner filter class.
	 */
    class MP3Filter extends javax.swing.filechooser.FileFilter
    {
    	public boolean accept(File file)
    	{
            String filename = file.getName();
            return file.isDirectory() || filename.endsWith(".mp3");
        }
        public String getDescription()
        {
            return "*.mp3";
        }
    }

	/***************************************************************************
	 * 							Controllers & World
	 ***************************************************************************/
	
	private World world;
	private ArtistController artistController; // ugly, @todo change!
	private TrackController trackController;

	/***************************************************************************
	 * 							Java stuff
	 ***************************************************************************/
	
	private static final long serialVersionUID = 1L;
}